#include "component/Renderer.h"
#include "GameObject.h"
#include "event/MessengerEventBase.h"
#include "component/Transform.h"



using namespace Boon;
using namespace Rendering;


Boon::Renderer::Renderer( const char* compName, Boon::GameObject* g )
	:	GameComponent( compName, g ),
		m_Material(),
		m_RenderPass( PASS_STATIC ),
		m_Messenger( Messenger::GetInstance() )
{
}

void Boon::Renderer::Update()
{
	Transform& t = GetGameObject().GetTransform();

	// if event already processed: create new
	if( m_EventUpdateNode.Expired() ||
		m_EventUpdateNode.Empty() )
	{
		Shared_ptr<Event_GameObject_Moved> event(
			new Event_GameObject_Moved( GetGameObject().GetUniqueObjectID() )
		);
		event->SetMatrix( &t.GetMatrixToWorld(), &t.GetMatrixFromWorld() );
		m_EventUpdateNode = event;

		// push to scene_node queue processed on start of render loop
		m_Messenger.BangQueued( event, QUEUETYPE_SCENENODE );
	}
	else // otherwise just update data stored in event
	{
		m_EventUpdateNode.Lock()->SetMatrix( &t.GetMatrixToWorld(), &t.GetMatrixFromWorld() );
	}
}

void Boon::Renderer::OnCreate()
{
	
}

void Boon::Renderer::OnStart()
{
	m_Messenger.Bang( GetEventCreateSceneNode() );
}

void Boon::Renderer::OnEnable()
{

}

void Boon::Renderer::OnDisable()
{

}

void Boon::Renderer::OnDestroy()
{

}

void Boon::Renderer::LateUpdate()
{

}
